location='https://github.com/cqregan/PUBPOL_543_01/raw/main/'
file='Use_Of_Force.csv'
link=paste0(location,file)
link
## [1] "https://github.com/cqregan/PUBPOL_543_01/raw/main/Use_Of_Force.csv"
#getting the data TABLE from the file in the cloud:
df = read.csv(file=url(link))
df
dfCleaned = df
dfCleaned["Precinct"][dfCleaned["Precinct"] == "X"] <- "Unknown"
dfCleaned["Precinct"][dfCleaned["Precinct"] == "0"] <- "Unknown"
dfCleaned["Precinct"][dfCleaned["Precinct"] == "-"] <- "Unknown"
dfCleaned
absoluteT=table(dfCleaned$Precinct,
exclude = 'nothing')
dfCleaned
prop.table(absoluteT)
##
## East North OOJ South Southwest Unknown
## 0.195899471 0.226124339 0.003835979 0.167460317 0.056679894 0.063822751
## West
## 0.286177249
propT=prop.table(absoluteT)*100
propT
##
## East North OOJ South Southwest Unknown West
## 19.5899471 22.6124339 0.3835979 16.7460317 5.6679894 6.3822751 28.6177249
(tableFreq=as.data.frame(absoluteT))
names(tableFreq)=c("Precinct","Count")
tableFreq$Percent=as.vector(propT)
tableFreq
library(ggplot2)
base= ggplot(data = tableFreq,
aes(x = Precinct,
y = Count))
plot1 = base + geom_bar(fill ="gray",
stat = 'identity')
plot1

titleText='How frequently do police precincts in Seattle use force?'
sourceText='Source: City of Seattle'
plot2 = plot1 + labs(title=titleText,
x =NULL,
y = NULL,
caption = sourceText)
plot2

tableFreq=tableFreq[order(tableFreq$Percent),]
# then:
tableFreq
(PrecinctOrd=tableFreq[order(tableFreq$Percent),'Precinct'])
## [1] OOJ Southwest Unknown South East North West
## Levels: East North OOJ South Southwest Unknown West
base= base + scale_x_discrete(limits=PrecinctOrd)
base= base + theme_classic()
##
plot1 = base + geom_bar(fill ="gray",
stat = 'identity')
plot2 = plot1 + labs(title=titleText,
x =NULL,
y = NULL,
caption = sourceText)
plot2
